<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JQuery写tab切换</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        div{
            display: none;
        }
        ul{
            width: 480px;
            border-bottom: 2px solid #0570ad;
            overflow: hidden;
        }
        li.rankTitle{
            float: left;
            text-align: center;
            width: 47%;
            list-style: none;
            margin: 0 5px;
            cursor: pointer;
            line-height: 30px;
        }
        .show{
            border-top-left-radius: 7px;
            border-top-right-radius: 7px;
            background-color: #0570ad ;
            color: #fff;
        }
        div.rankTab{
            margin-top: 5px;
            width: 480px;
            height: 250px;
            /*border: 1px solid black;*/
            background-color: #0570ad;
            color: #fff;
            cursor: pointer;
            text-align: center;
            line-height: 250px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<ul>
    <li class="show rankTitle">标题1</li>
    <li class="rankTitle">标题2</li>
</ul>
<div class="show0 rankTab" style="display: block;">第一部分</div>
<div class="show1 rankTab">第二部分</div>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    $('li').hover(function(){
        //获取所有的li标签并移除类
        $(this).siblings().removeClass('show');
        //给当前的li添加类
        $(this).addClass('show');
        //隐藏所有的div
        $('div').hide();
        //获取当前li的索引
        var index=$('li').index($(this));
        //拼凑相应的div的类
        var index1='show'+index;
        //根据相应的类显示相应的div
        $('div.'+index1).show();
    })
</script>
</body>
</html>